const DB = wx.cloud.database()
let that;
let sc_list=[];
Page({

  /**
   * 页面的初始数据
   */
  data: {
    sc_list:[]
  },
  nav_user_detail(e){
    console.log('e',e)
    var userInfo = e.currentTarget.dataset.item
    wx.setStorageSync('seeuserInfo', userInfo)
    wx.navigateTo({
      url: '/pages/user_detail/user_detail',
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    that=this
    console.log('sc_list11111111',sc_list)
    sc_list=[]
    DB.collection('shouchang').where({
      _openid: wx.getStorageSync('userInfo')._openid,
    })
    .get({
      success: function(res) {
        console.log(res.data)
        let shouchang_list=res.data[0].shouchang_list
        
        that.sousuo(shouchang_list).then(ress=>{
          console.log('sc_list222222222',sc_list)
          setTimeout(() => {
            that.setData({
              sc_list:sc_list
            })
          }, 500);
        });
      }
    })
  },
  sousuo(list){
    return new Promise(ss=>{
      list.forEach((value, i) => {
        console.log('i:', i, 'value:', value)
        DB.collection('user').where({
          _openid: value,
        })
        .get({
          success: function(res) {

            sc_list.push(res.data[0])
            if(i==list.length-1){
              ss(true)
            }
          }
        })
      })
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

})